<template>
  <el-main>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home/index/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>{{ breadcrumbNameP }}</el-breadcrumb-item>
      <el-breadcrumb-item>{{ breadcrumbName }}</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- <h3 style="margin-top:20px">基本信息</h3>
    <el-form ref="editForm"
             :model="editForm"
             label-width="100px"
             style="width:50%;"
             :rules="rules">
      <el-form-item label="角色类型"
                    prop="role_name">
        <el-input v-model="editForm.role_name"
                  :disabled="true"
                  autocomplete='off'></el-input>
      </el-form-item>
      <el-form-item label="登录名"
                    prop="user_name">
        <el-input v-model="editForm.user_name"
                  :disabled="true"
                  autocomplete='off'></el-input>
      </el-form-item>
      <el-form-item label="昵称"
                    prop="nick_name">
        <el-input v-model="editForm.nick_name"
                  autocomplete='off'></el-input>
      </el-form-item>
      <el-form-item label="是否修改密码">
        <el-switch v-model="isEditPassword"
                   autocomplete='off'></el-switch>
      </el-form-item>
      <template v-if="isEditPassword">
        <el-form-item label="登录密码"
                      prop="password"
                      :rules="[
                { required: true, message:  '密码不能为空', trigger: 'blur' },
                { min: 6, max: 30, message:  '密码长度不少于6位', trigger: 'blur' }
                ]">
          <el-input placeholder="请输入"
                    v-model="editForm.password"
                    show-password
                    autocomplete='off'>
          </el-input>
        </el-form-item>
        <el-form-item label="确认密码"
                      prop="confirm_password">
          <el-input placeholder="请输入"
                    v-model="editForm.confirm_password"
                    show-password
                    autocomplete='off'>
          </el-input>
        </el-form-item>
      </template>
    </el-form>
    <div style="text-align: center;width: 50%">
      <el-button @click="handleEdit">重 置</el-button>
      <el-button type="primary"
                 :disabled="editDisabled"
                 @click="editSubmit('editForm')">提 交</el-button>
    </div> -->
    <div >
      <h3>{{settingForm.CompanyName}}</h3>
      <el-form ref="settingForm"
               :model="settingForm"
               label-width="150px"
               style="width:50%;"
               :rules="rules">
        <el-form-item label="所属公司">
          <el-input v-model="settingForm.CompanyName"
                    :disabled="true"
                    autocomplete='off'></el-input>
        </el-form-item>
        <el-form-item label="DC名称"
                      prop="DeptName"
                      :rules="{ required: true, message: '请输入DC名称', trigger: 'blur' }">
          <el-input v-model="settingForm.DeptName"
                    autocomplete='off' placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="DC地址"
                       prop="Location"
                      :rules="{ required: true, message: '请输入DC地址', trigger: 'blur' }">
          <el-input v-model="settingForm.Location"
                    autocomplete='off' placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="负责人">
          <el-input v-model="settingForm.DispatchName"
                    autocomplete='off' placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="settingForm.Phone"
                    autocomplete='off' placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="主任手机号">
          <el-input v-model="settingForm.DirectorLinkphone"
                    autocomplete='off' placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="调度手机号">
          <el-input v-model="settingForm.DispatchLinkPhone"
                    autocomplete='off' placeholder="请输入"></el-input>
        </el-form-item>
        
      </el-form>
      <div style="text-align: center;width: 50%">
        <el-button @click="getCarrierInfo">重 置</el-button>
        <el-button type="primary"
                   :disabled="editDisabledC"
                   @click="saveCarrierInfo('settingForm')">提 交</el-button>
      </div>
    </div>
  </el-main>
</template>
<script>
import {
  mapState
} from 'vuex'
import {
  infoDept,
  infoupadet
  } from '../../api.js'
export default {
  name: "basicInformation",
  data () {
    return {
      breadcrumbName: '',
      breadcrumbPath: '',
      breadcrumbNameP: '',
      isEditPassword: false,
      is_carrier: false,
      editDisabled: false,
      editDisabledC: false,
       settingForm: {
        admin_id:0,
        CompanyName:'',
        DeptId:0,
        DeptName:'',
        Location:'',
        DispatchName:'',//主管
        Phone:'',
        DirectorLinkphone:'',//主任
        DispatchLinkPhone:'',
        // ForceAssignWaitMin:'',
        // WithdrawMin:'',
      },
      rules:{},
    }
  },
  mounted () {
    this.breadcrumbName = this.$route.query.breadcrumbName
    this.breadcrumbPath = this.$route.query.breadcrumbPath
    this.breadcrumbNameP = this.$route.query.breadcrumbNameP
    this.getCarrierInfo()
  },
  methods: {
    getCarrierInfo () {
      var _this = this;
      infoDept().then(res => {
          if (res.ErrorCode == 0) {
            _this.settingForm.admin_id = res.Data.list.admin_id
            _this.settingForm.DeptId = res.Data.list.dept_id
            _this.settingForm.CompanyName = res.Data.list.company_name
            _this.settingForm.DeptName = res.Data.list.full_name
            _this.settingForm.Location = res.Data.list.location
            _this.settingForm.DispatchName = res.Data.list.director_name
            _this.settingForm.Phone = res.Data.list.phone
            _this.settingForm.DirectorLinkphone = res.Data.list.director_link_phone
            _this.settingForm.DispatchLinkPhone = res.Data.list.dispatch_link_phone
          } else {
            this.$message.error(res.ErrorMsg);
          }
        })
    },
    saveCarrierInfo(formName) {
      var _this = this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          _this.editDisabledC = true;
          // var dataObj = JSON.parse(JSON.stringify(_this.settingForm)) ;
          var dataObj = {
            admin_id:_this.settingForm.admin_id,
            phone:_this.settingForm.Phone,
            dept_id:_this.settingForm.DeptId,
            full_name:_this.settingForm.DeptName,
            location:_this.settingForm.Location,
            director_name:_this.settingForm.DispatchName ,
            director_link_phone: _this.settingForm.DirectorLinkphone,
            dispatch_link_phone:_this.settingForm.DispatchLinkPhone,
          }
          infoupadet(dataObj).then(res => {
            if (res.ErrorCode == 0) {
              _this.editDisabledC = false;
              _this.getCarrierInfo()
            } else {
               _this.editDisabledC = false;
              this.$message.error(res.ErrorMsg);
            }
          })
          }
      })
    },
  },
  computed: {
    ...mapState({
      access_token: state => state.access_token,
      baseUrl: state => state.baseUrl,
    }),
  },
}
</script>

<style>
</style>